package src;

import java.net.ServerSocket;
import java.io.IOException;

public class Main
{
    public static Main m;
    public ConnectionManager cm;
    private Processor pr;
    public GameEngine ge;
    public ServerSocket socket;
    private int serverPort = 43594;

    public Main()
    {
    }

    public static void main(String[] args)
    {
        m = new Main();
        try
        {
            m.socket = new ServerSocket(m.serverPort, 1, null);
            //m.socket.setSoTimeout(100);
            m.log("Starting server on port " + m.serverPort);
        }
        catch(IOException ioe)
        {
            m.log("Port " + m.serverPort + " already in use.");
            return;
        }
        m.ge = new GameEngine();
        m.ge.load();
        m.pr = new Processor();
        m.cm = new ConnectionManager();
        m.newThread(m.cm);
        m.newThread(m.pr);
    }

    private void newThread(Runnable r)
    {
        (new Thread(r)).start();
    }

    public void log(String s)
    {
        System.out.println(s);
        s = null;
    }
}